package com.aperos.webservice;

import java.io.IOException;
import java.util.List;
import java.util.logging.Logger;

import javax.jdo.PersistenceManager;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@SuppressWarnings("serial")
public class GetAllBarErrorsServlet extends HttpServlet {
    private static final Logger log = Logger.getLogger(GetAllBarErrorsServlet.class.getName());

    @SuppressWarnings("unchecked")
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
                throws IOException {
    	PersistenceManager pm = PMF.get().getPersistenceManager();
        String query = "select from " + BarError.class.getName();
        List<BarError> barErrors = (List<BarError>) pm.newQuery(query).execute();
        if (barErrors.isEmpty()) {
        	resp.setContentType("text/plain");
        	resp.getWriter().println("No bar Error");
        } else {
        	resp.setContentType("text/plain");
            for (BarError barError : barErrors) {
            	String id = String.valueOf(barError.getKey().getId());
            	String refBarError = String.valueOf(barError.getRefBarError());
            	String barErrorMessage = barError.getBarErrorMessage();
            	String barErrorComment = barError.getBarErrorComment();
            	String barErrorState = barError.getBarErrorState();
            	
            	
            	String response = id + "|" + refBarError + "|" + barErrorMessage + "|" + barErrorComment+ "|" + barErrorState;
            	
        		resp.getWriter().println(response);
            }
        }
        pm.close();

    }
}